from moodlefuse.moodle import Moodle
from moodlefuse.fuse import FUSE
import wx
from wx.lib.wordwrap import wordwrap

class Client(wx.App):

   def __init__(self, redirect=False, filename=None):
       wx.App.__init__(self, redirect, filename)
       self.frame = wx.Frame(None, wx.ID_ANY, title='Prijava', size=(550,250))

       self.panel = wx.Panel(self.frame, wx.ID_ANY)
       welcomeText = wordwrap(
            "Tu se prijavite s svojim uporabniskim imenom (username@student.uni-lj.si oz. username@fri1.uni-lj.si)."
            " Studenti potrebujejo digitalno identiteto, ki jo pridobijo na https://id.uni-lj.si in jo uporabljajo"
            " tudi za racunalniske ucilnice in eduroam.",
            400, wx.ClientDC(self.panel))
       wx.StaticText(self.panel, -1, welcomeText, (85,15), (-1,-1), wx.ALIGN_CENTER)
            # copy the code for the AboutBox

       wx.StaticText(self.panel, -1, "Uporabnisko ime", (40,120), (200,-1), wx.ALIGN_RIGHT)
       wx.StaticText(self.panel, -1, "Geslo", (40,151), (100,-1), wx.ALIGN_RIGHT)
       self.username = wx.TextCtrl(self.panel, -1, '', (200, 117), (300,-1))
       self.password = wx.TextCtrl(self.panel, -1, '', (200, 147), (300,-1), wx.TE_PASSWORD)

       # change the button's parent to refer to my panel
       b = wx.Button(self.panel, -1, "Prijava", (400,180), (100,-1))
       self.Bind(wx.EVT_BUTTON, self.login_fuse, b)

       sb = wx.Button(self.panel, -1, "Nastavitve", (200,180), (100,-1))
       self.mount_point = self.Bind(wx.EVT_BUTTON, self.select_folder, sb)

       self.frame.Show()

   def login_fuse(self, evt):
       fuse = FUSE(Moodle(self.username.GetValue(), self.password.GetValue()), self.mount_point, foreground=True, debug=True)
       print(self.username.GetValue())
       print(self.password.GetValue())

   def select_folder(self, evt):
       userPath = '/home'

       dialog = wx.DirDialog(self.panel, "Prosim izberite lokacijo:", style=1 ,defaultPath=userPath, pos = (10,10));
       if dialog.ShowModal() == wx.ID_OK:
           _selectedDir = dialog.GetPath()
       else:
           _selectedDir = ""
       return _selectedDir

if __name__ == '__main__':
   app = Client()
   app.MainLoop()